//
//  invation_Cell.m
//  penzer
//
//  Created by caiyc on 2018/10/3.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "invation_Cell.h"

@implementation invation_Cell
-(NSString *)getMMSSFromSS:(NSInteger )totalTime{
    NSInteger seconds = totalTime;
    NSInteger hour = seconds/3600;
    NSString *str_hour = [NSString stringWithFormat:@"%ld",seconds/3600];
    //format of minute
    NSInteger minute = (seconds%3600)/60;
    NSString *str_minute = [NSString stringWithFormat:@"%ld",(seconds%3600)/60];
    //format of second
   // NSString *str_second = [NSString stringWithFormat:@"%ld",seconds%60];
    NSString *format_time =@"";
    if(hour==0){
        format_time =[NSString stringWithFormat:@"%@分钟",str_minute];
    }
    if(hour>0&&minute==0){
        format_time =[NSString stringWithFormat:@"%ld小时",(long)hour];
    }
    if(hour>0&&minute>0){
        format_time = [NSString stringWithFormat:@"%@小时%@分钟",str_hour, str_minute];
    }
   
    return format_time;
}
-(void)bindData:(NSDictionary *)dic{
    NSDictionary *goodDic = dic[@"goods_list"][0];
    NSURL *goodImg = [NSURL URLWithString:goodDic[@"thumb"]];
    [self.goodsImg sd_setImageWithURL:goodImg];
    self.goodPrice.text = [NSString stringWithFormat:@"¥%@",goodDic[@"buy_price"]];
    self.goods_Num.text = [NSString stringWithFormat:@"%lu件商品",[dic[@"goods_list"]count]];
    self.good_Name.text = goodDic[@"title"];
    self.maxNum.text = [NSString stringWithFormat:@"%@人",dic[@"member_max"]];
    self.liveSaleTYpe.text = dic[@"live_type_cn"];
    NSURL *logo = [NSURL URLWithString:dic[@"logo"]];
    [self.logo sd_setImageWithURL:logo];
    self.store_name.text = dic[@"title"];
    NSString *timeformat = [XTool timeFrommartTotimeintral:dic[@"start_time"]];
    self.live_Time.text = [NSString stringWithFormat:@"开播时间：%@",timeformat];
    NSInteger start = [dic[@"start_time"]integerValue];
    NSInteger end = [dic[@"end_time"]integerValue];
    NSInteger total = end-start;
    NSString *str = [self getMMSSFromSS:total];
    [self.total_times setTitle:str forState:UIControlStateNormal];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.time_BottomView3.layer.cornerRadius = 12;
    self.time_BottomView3.layer.masksToBounds = 1;
    
    self.time_BottomView1.layer.cornerRadius = 12;
    self.time_BottomView1.layer.masksToBounds = 1;
    
    self.time_BottomView2.layer.cornerRadius = 12;
    self.time_BottomView2.layer.masksToBounds = 1;
    
    self.contact_Btn.layer.cornerRadius = 15;
    self.contact_Btn.layer.masksToBounds = 1;
    
    self.checktime_Btn.layer.cornerRadius = 15;
    self.checktime_Btn.layer.masksToBounds = 1;
    self.acpt_Btn.layer.cornerRadius = 15;
    self.acpt_Btn.layer.masksToBounds = 1;
    self.deni_Btn.layer.cornerRadius = 15;
    self.deni_Btn.layer.masksToBounds = 1;
    
    self.live_times.layer.cornerRadius = 5;
    self.live_times.layer.masksToBounds = 1;
    // Initialization code
}
- (IBAction)call:(UIButton *)sender {
    self.call();
}
- (IBAction)acpct:(UIButton *)sender {
    self.handelInvation(sender.tag);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
